package com.han.agent.mcp;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author han
 */
@RestController
@RequestMapping("/mcp")
public class McpClient {

    private final ChatClient chatClient;

    public McpClient(ChatClient.Builder chatClientBuilder, ToolCallbackProvider toolCallbackProvider) {
        this.chatClient = chatClientBuilder.defaultToolCallbacks(toolCallbackProvider).build();
    }

    @GetMapping("/chat")
    public String mcpChat(@RequestParam(required = false, defaultValue = "深圳到北京路线") String message) {
        return chatClient
                .prompt(message)
                .call()
                .content();
    }
}
